package com.ruoyi.manage.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.manage.domain.ServiceType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.manage.domain.ServiceItem;
import com.ruoyi.manage.service.IServiceItemService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 服务项管理Controller
 * 
 * @author ruoyi
 * @date 2024-05-24
 */
@RestController
@RequestMapping("/item")
public class ServiceItemController extends BaseController
{
    @Autowired
    private IServiceItemService serviceItemService;

    /**
     * 查询服务项管理列表
     */
    @RequiresPermissions("manage:item:list")
    @GetMapping("/list")
    public TableDataInfo list(ServiceItem serviceItem) {
        startPage();
        List<ServiceItem> list = serviceItemService.selectServiceItemList(serviceItem);
        return getDataTable(list);
    }

    /**
     * 导出服务项管理列表
     */
    @RequiresPermissions("manage:item:export")
    @Log(title = "服务项管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServiceItem serviceItem)
    {
        List<ServiceItem> list = serviceItemService.selectServiceItemList(serviceItem);
        ExcelUtil<ServiceItem> util = new ExcelUtil<ServiceItem>(ServiceItem.class);
        util.exportExcel(response, list, "服务项管理数据");
    }

    /**
     * 获取服务项管理详细信息
     */
    @RequiresPermissions("manage:item:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(serviceItemService.selectServiceItemById(id));
    }

    /**
     * 新增服务项管理
     */
    @RequiresPermissions("manage:item:add")
    @Log(title = "服务项管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServiceItem serviceItem)
    {
        return toAjax(serviceItemService.insertServiceItem(serviceItem));
    }

    /**
     * 修改服务项管理
     */
    @RequiresPermissions("manage:item:edit")
    @Log(title = "服务项管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServiceItem serviceItem)
    {
        return toAjax(serviceItemService.updateServiceItem(serviceItem));
    }

    /**
     * 删除服务项管理
     */
    @RequiresPermissions("manage:item:remove")
    @Log(title = "服务项管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(serviceItemService.deleteServiceItemByIds(ids));
    }

    /**
     * @Author 黄春雨
     * @Description //TODO  修改服务状态
     * @Date 9:23 2024/5/24
     * @Param
     * @param id
     * @param status
     * @return com.ruoyi.common.core.web.domain.AjaxResult
     */
    @RequiresPermissions("manage:item:enabledState")
    @Log(title = "服务类型管理", businessType = BusinessType.UPDATE)
    @PutMapping("/enabledState/{id}/{status}")
    public AjaxResult enabledState(@PathVariable Long id, @PathVariable Long status) {

        return toAjax(serviceItemService.updateEnabledState(id,status));
    }



    /**
    * @Author 黄春雨
    * @Description //TODO  服务类型列表
    * @Date 14:55 2024/5/24
    * @Param
    * @return com.ruoyi.common.core.web.domain.AjaxResult
    */
    @RequiresPermissions("manage:item:serviceTypeList")
    @Log(title = "服务类型管理", businessType = BusinessType.EXPORT)
    @GetMapping("/serviceTypeList")
    public AjaxResult serviceTypeList() {
      List<ServiceType> list=  serviceItemService.serviceTypeList();
        return success(list);
    }


    /**
    * @Author 黄春雨
    * @Description //TODO  根据类型id查询服务列表
    * @Date 9:49 2024/5/25
    * @Param
     * @param serverTypeId
    * @return com.ruoyi.common.core.web.page.TableDataInfo
    */

    @RequiresPermissions("manage:item:listItemTypeId")
    @GetMapping("/listItemTypeId/{serverTypeId}")
    public AjaxResult listItemTypeId(@PathVariable Long serverTypeId) {
        List<ServiceItem> list = serviceItemService.selectServicelistItemTypeId(serverTypeId);
        return success(list);
    }

    /**
     * @Author 黄春雨
     * @Description //TODO 根据id查询服务列表
     * @Date 14:27 2024/5/25
     * @Param
     * @param ids
     * @return com.ruoyi.common.core.web.domain.AjaxResult
     */
    @RequiresPermissions("manage:areaItem:listItemId")
    @GetMapping("listItemId/{ids}")
    public AjaxResult listItemId(@PathVariable List<Long> ids){
        return success(serviceItemService.selectListItemId(ids));
    }



    @RequiresPermissions("manage:areaItem:selectServiceName")
    @GetMapping("selectServiceName/{serviceName}")
    public AjaxResult selectserviceName(@PathVariable String serviceName){
        return success(serviceItemService.selectServiceName(serviceName));
    }

}
